<style scoped>
  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }
  .weui-loadmore_line .weui-loadmore__tips {
    background-color: #eee;
  }
  .rj-cell.max span{
    font-size: 16px;
    padding-right: 20px;
  }
  .rj-cell label {
    color: #333;
    font-size: 14px;
    width: 44%;
    display: inline-block;
    padding: 5px 3%;
    text-align: right;
  }
  .rj-cell span {
    font-size: 14px;
    color: #333;
    display: inline-block;
    width: 50%;
  }
  .rj-cell.note label{
    float: left;
  }
  .rj-cell.note span{
    width: 80%;
    display: inline-block;
  }
  .weui-cells {
    margin-top: 0;
  }
  .weui-cells_form {
    background: #fbfbfb;
  }
  .weui-cell {
    background: #fff;
  }
  .weui-cells__title {
    text-align: left;
  }
  .oitem {
    padding: 3px;
  }
  .hide {
    display: none;
  }
  #acts {
    font-size: 0;
  }
  #acts span {
    font-size: 14px;
  }
  .halfbtn {
    display: inline-block;
    width: 49%;
  }

  .clearfix:after {
    content: ".";
    display: block;
    font-size: 0;
    height: 0;
    clear: both;
    visibility: hidden;
  }
  .clearfix {
    display: inline-table;
  }
  *html .clearfix {
    height: 1%;
  }
  .clearfix {
    display: block;
  }
  *+html .clearfix {
    min-height: 1%;
  }
  .che_tit{
    text-align:center;
    padding:20px;
  }
  .ul_pro{
    background-color:#CED3D9;
    text-align:center;
    padding:4px 2px;
    font-size:14px;
  }
  .ul_pro li{
    float:left;
    width:11.11%;
    padding:2px;
    box-sizing: border-box;
    list-style: none;
  }
  .ul_pro .li_close{
    float:right;
    width:22.22%;
  }
  .ul_pro .li_close span{
    background-color:#ACB3BB;
  }
  .ul_pro .li_clean{
    float:right;
    width:22.22%;
  }
  .ul_pro li span{
    display:block;
    background-color:#fff;
    border-radius:4px;
    box-shadow: 2px 2px 2px #888888;
    /* max-width:48px; margin:0 auto; */
    line-height:32px;
    padding-top:2px;
  }
  .ul_pro li span:active{
    background-color:#4DA9F2;
    color:#fff;
  }
  .ul_input{
    width:auto;
    margin:0 auto;
  }
  .ul_input li{
    float:left;
    width:12%;
    padding:2px;
    text-align:center;
    list-style: none;
  }
  .ul_input li span{
    display: block;
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    width: 30px;
    margin: 0 auto;
    height: 30px;
    line-height: 30px;
  }
  .ul_keybord{
    background-color:#CED3D9;
    text-align:center;
    padding:4px 2px;
    font-size:14px;
  }
  .ul_keybord li{
    float:left;
    width:10%;
    padding:2px;
    box-sizing: border-box;
    list-style: none;
  }
  .ul_keybord .ikey20{
    margin-left:5%;
  }
  .ul_keybord .li_w{
    width:11.11%;
  }
  .ul_keybord .li_close{
    float:right;
    width:22.22%;
  }
  .ul_keybord .li_close span{
    background-color:#ACB3BB;
  }
  .ul_keybord .li_clean{
    float:right;
    width:22.22%;
  }
  .ul_keybord li span{
    display:block;
    background-color:#fff;
    border-radius:4px;
    box-shadow: 2px 2px 2px #888888;
    /* max-width:48px; margin:0 auto; */
    line-height:32px;
    padding-top:2px;
  }
  .ul_keybord li span:active{
    background-color:#4DA9F2;
    color:#fff;
  }
  .weui-label{
    width: 130px;
  }
</style>
<template>
  <div>
    <div class="rj-wrap">
      线路调整
      <a href="javascript:;" @click="$router.back(-1)" style="position: absolute; left: 10px; top: 8px">
        <img src="@/assets/back.png" style="width: 20px" />
      </a>
    </div>
    <div class="weui-cells weui-cells_form">
<!--      <form action="/sales/Sellform!saveOrUpdate.action?openid=${openid}" method="post" id="formid">-->
      <form method="post" id="formid">
        <input  name="farepricetype"  id="farepricetype"  :value="adata.farepricetype"  type="hidden"  />
        <!--<input  name="unloaddesc"  id="unloaddesc"  :value="adata.unloaddesc"   type="hidden"  />-->
        <input  name="guid"  id="guid"   type="hidden"  :value="guid" />
        <input  name="sellType"  id="sellType"   type="hidden"  value="editLine" />
        <input  name="wlcompanyguid"  id="wlcompanyguid"  :value="adata.wlcompanyguid"  type="hidden"   />

         <div class="weui-cell">
          <div class="weui-cell__hd"><label class="weui-label">订单编号：</label></div>
          <div class="weui-cell__bd">
            <input class="weui-input" type="text" readonly id="sellcode" :value="adata.sellcode" name="sellcode" placeholder="请输入订单编号">
          </div>
        </div>
        <div class="weui-cell">
          <div class="weui-cell__hd"><label class="weui-label">申请人：</label></div>
          <div class="weui-cell__bd">
            <input class="weui-input" id="applyname" readonly  type="text"  name="applyname" :value="adata.applyname" placeholder="请输入申请人">
          </div>
        </div>
<!--        <div class="weui-cell">-->
<!--          <div class="weui-cell__hd"><label class="weui-label">是否压车：</label></div>-->
<!--          <div class="weui-cell__bd">-->
<!--            <input class="weui-input" type="text" id="unloaddesc" readonly="true" name="unloaddesc"  :value="adata.unloaddesc" placeholder="请选择是否压车" >-->

<!--          </div>-->
<!--        </div>-->
        <div class="weui-cell">
          <div class="weui-cell__hd"><label class="weui-label">物流公司：</label></div>
          <div class="weui-cell__bd">
            <input class="weui-input" type="text" id="wlcompany" name="wlcompany" :value="adata.wlcompany" placeholder="请输入物流公司" >
          </div>
        </div>
        <div class="weui-cell">
          <div class="weui-cell__hd"><label class="weui-label">司机姓名：</label></div>
          <div class="weui-cell__bd">
            <input class="weui-input" type="text" readonly id="drivername" name="drivername" :value="adata.drivername" placeholder="请输入司机姓名">
          </div>
        </div>
        <div class="weui-cell">
          <div class="weui-cell__hd"><label class="weui-label">司机电话：</label></div>
          <div class="weui-cell__bd">
            <input class="weui-input" type="text" readonly id="driverphone" name="driverphone" :value="adata.driverphone" placeholder="请输入司机联系电话" >
          </div>
        </div>



        <div class="weui-cell">
          <div class="weui-cell__hd"><label class="weui-label">车牌号：</label></div>
          <div class="weui-cell__bd">
            <input class="weui-input" type="text" readonly id="carcode" name="carcode" :value="adata.carcode" placeholder="请输入车牌号">
          </div>
        </div>









        <div class="weui-cells weui-cells_form">
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">运价方式：</label></div>
            <div class="weui-cell__bd">
              <input class="weui-select" readonly  type="text"  id="farePriceTypeC" name="farePriceTypeC"  placeholder="请选择运价方式">
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">运价：</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" readonly type="number" id="fareprice" name="fareprice" :value="adata.fareprice"  placeholder="请输入运价">
            </div>
          </div>





          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">发货联系人：</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input"  readonly  id="deliContact" name="deliContact" :value="adata.deliContact"  placeholder=" 请输入发货联系人">
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">联系电话</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" readonly type="number" id="deliContactNo" name="deliContactNo" :value="adata.deliContactNo"  placeholder=" 请输入联系电话">
            </div>
          </div>

          <div class="weui-cell">
            <div class="weui-cell__hd"><label id='unqualifiedchkrateDiv' class="weui-label">发货地址：</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" readonly type="text" id='deliProvince' name="deliProvince" >
            </div>
          </div>

          <div class="weui-cell">
            <div class="weui-cell__hd"><label  class="weui-label">详细地址:</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" readonly type="text" id='deliAddress' name="deliAddress" :value="adata.deliAddress" placeholder=" 请输入详细地址">
            </div>
          </div>








          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">收货联系人：</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input"    id="arriContact" name="arriContact" :value="adata.arriContact"  placeholder="请输入收货联系人">
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">联系电话:</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="number" id="arriContactNo" name="arriContactNo" :value="adata.arriContactNo"  placeholder=" 请输入收货人手机号">
            </div>
          </div>

          <div class="weui-cell">
            <div class="weui-cell__hd"><label   class="weui-label">收货地址：</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="text" id='arriProvince' name="arriProvince" >
            </div>
          </div>

          <div class="weui-cell">
            <div class="weui-cell__hd"><label  class="weui-label">详细地址:</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="text" id='arriAddress' name="arriAddress" :value="adata.arriAddress" placeholder=" 请输入收货详细地址">
            </div>
          </div>
        </div>
        <div ref="actHtml" class="fixcont">
          <div class="weui-btn-area">
            <a class="weui-btn weui-btn_primary halfbtn subbtn" href="javascript:" @click="send">保存</a>
            <a class="weui-btn weui-btn_primary halfbtn" href="javascript:" @click="$router.back(-1)" id="sub">取消</a>
          </div>
        </div>
      </form>
    </div>
    <div id="bmlogs">
      <SalesOperationLogs2 :nodeid="nodeid" :orderid="guid" :srguid="adata.storermguid" :departid="adata.depguid"></SalesOperationLogs2>
    </div>
  </div>
</template>

<script>
  import SalesOperationLogs2 from '../common/SalesOperationLogs2'

  export default {
  name: 'EditLine',

  data () {
    return {
      guid : "",
      nodeid: '',
      status: '',
      adata: {}
    }
  },
    components: {
      SalesOperationLogs2
    },
  mounted () {
    //提交操作定位到页面底部
    //$('#bmlogs').css('margin-bottom', this.$refs.actHtml.offsetHeight)

    let that = this;

    this.guid = this.$route.query.guid;
    this.nodeid = this.$route.query.nodeid;

        //获取回显数据
        $.ajax({
          url: '/sales/Sellform!toSendCar.action',
          data: {guid:that.guid},
          type: "post",
          dataType: "json",
          success: function(res) {
            console.log(res);
            if (res.info != undefined) {
              that.adata = res.info;
              $('#orgguid').val(res.info.orgguid);
              $('#deliProvince').val(res.info.deliProvince + " " + res.info.deliCity + " " +res.info.deliDistrict);
              $('#arriProvince').val(res.info.arriProvince + " " + res.info.arriCity + " " +res.info.arriDistrict);



              //运价方式
              $('#farepricetype').val(res.info.farepricetype);
              if(res.info.farepricetype == 1){
                $('#farePriceTypeC').val("按车");

              }else{
                $('#farePriceTypeC').val("按吨");
              }
              } else {
              that.toastError('系统出现异常!');

            }
          },
          complete: function () {

          }
        });



    //获取回显数据
    $.ajax({
      url: '/sales/Sellform!getWlCompany.action',
      data: {},
      type: "post",
      dataType: "json",
      success: function(res) {
        if (res.info != null) {
          var data = res.info.result;
          data = eval('(' + data+ ')');
          var datalist = new Array;

          $.each( data.result, function( index, itsm ) {
            var info = { "title": itsm.name, "value": itsm.guid };
            datalist.push(info);
          });

          $('#wlcompany').select({
            title: "物流公司",
            items: datalist,
            onChange: function (data) {
              $('input[name="wlcompanyguid"]').val($('#wlcompany').data('values'));
            }
          });
        } else {
          that.toastError('系统出现异常!');
        }
      },
      complete: function () {

      }
    });



//
//    $('#unloaddescC').select({
//      title: "选择是否压车",
//      items: [
//        {
//          title: "是",
//          value: "1",
//        },
//        {
//          title: "否",
//          value: "2",
//        }
//      ],
//      onChange: function (data) {
//      $('input[name="unloaddesc"]').val($('#unloaddescC').data('values'));
//    }
//    });

//    $('#farePriceTypeC').select({
//      title: "运价方式",
//      items: [
//        {
//          title: "按车",
//          value: "1",
//        },
//        {
//          title: "按吨",
//          value: "2",
//        }
//      ],
//      onChange: function (data) {
//        $('input[name="farepricetype"]').val($('#farePriceTypeC').data('values'));
//      }
//    });




//    $("#deliProvince").cityPicker({
//      title: "请选择发货地址",
//    });
    $("#arriProvince").cityPicker({
      title: "请选择收货地址"
    });


    //编辑车牌号后赋值
    $(".input_pp span").bind("DOMNodeInserted",function(e){

      var car = $('#cn0').text() + $('#cn1').text() + $('#cn2').text() + $('#cn3').text() + $('#cn4').text() + $('#cn5').text() + $('#cn6').text();
      console.log("carcode",car);
      $('#carcode').val(car);
    })



  },
  methods: {
    send: function() {
      let that = this;

      if(!checkSubmit()){
        return;
      }
      //防止重复提交
      $('.subbtn').attr("disabled",true).css("pointer-events","none");
        //显示提交状态
        $.showLoading("正在提交");

      this.axios({
        method: 'post',
        responseType: 'json',
        headers: { "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8" },
        url: '/sales/Sellform!sendCar.action?nodeid=' + this.nodeid,
        params: this.serialize2Obj($("#formid").serializeArray())
      }).then(response => {
        //恢复提交按钮可点击
        $('.subbtn').attr('disabled', false).css("pointer-events","auto");
          //关闭提交状态
          $.hideLoading();

        // if(response.data.info == "ok"){
        //
        //   this.toastText('操作成功!');
        // }else{
        //   this.toastText('操作失败!');
        //
        // }
        if(response.data.info == "ok"){
          this.toastSuccess('操作成功!');
        } else if (response.data.info == 'canotopt') {
          this.toastText('不允许的操作！');
        }else{
          this.toastText('操作失败!');

        }
        this.$router.push({name: 'Sellform'});
      }).catch(function (error) {
        //恢复提交按钮可点击
        $('.subbtn').attr('disabled', false).css("pointer-events","auto");
          //关闭提交状态
          $.hideLoading();
        that.toastError('系统错误');
      });

    },
    serialize2Obj: function (data) {
      var obj = {};
      $.each(data,function(i,v){
        obj[v.name] = v.value;
      })
      return obj;
    },
    openLogs: function() {
      this.$router.push({name: 'SalesOperationLogs2', query: {orderid: this.guid, srguid: this.adata.storermguid, departid: this.adata.depguid}});
    }

  }
}

/**
 * 提交之前的校验
 */
function checkSubmit(){

    //物流公司
    if(isEmpty("drivername")){
        alert("请填写司机姓名");
        return false;
    }
    if(isEmpty("driverphone")){
      alert("请填写司机电话");
      return false;
    }
    if(isEmpty("carcode")){
      alert("请填写车牌号");
      return false;
    }
    if(isEmpty("farePriceType")){
      alert("请选择运价方式");
      return false;
    }

    if(isEmpty("fareprice")){
      alert("请填写运价");
      return false;
    }




    if(isEmpty("deliContact")){
      alert("请填写发货联系人");
      return false;
    }
    if(isEmpty("deliContactNo")){
      alert("请填写发货联系人手机号");
      return false;
    }
    if(isEmpty("deliProvince")){
      alert("请填写发货地址");
      return false;
    }
    if(isEmpty("deliAddress")){
      alert("请填写发货详细地址");
      return false;
    }


    if(isEmpty("arriContact")){
      alert("请填写收货联系人");
      return false;
    }
    if(isEmpty("arriContacttel")){
      alert("请填写收货联系人手机号");
      return false;
    }if(isEmpty("arriProvince")){
      alert("请填写收货地址");
      return false;
    }if(isEmpty("arriAddress")){
     alert("请填写详细收货地址");
      return false;
    }
  return true;
}

function isEmpty(domID){

  return $('#' + domID).val() == "" || $('#' + domID) == null;
}


</script>
